const jwt = require('jsonwebtoken');

const secret = 'rbydxhq';

const createToken = (username, id, expires, strTimer) => {
    let token = jwt.sign({
        User: username,
        _id: id
    }, secret, {
        expiresIn: expires + " " + strTimer
    });
    return token;
}

//let serverToken = createToken("admin", "WEB", "7", "days");
//let localToken = createToken("admin", "WEB", "2", "hours");
//console.log(serverToken);
//console.log(localToken);

const verifyToken = (_token) => {
    let verify = jwt.verify(_token, secret, (error, decoded) => {
        if(error) {
            return "Token Invalid";
        }
        return decoded;
    });
    return verify;
};

//console.log(verifyToken("123123123"));
exports.createToken = createToken;
exports.verifyToken = verifyToken;
